import { httpRequest } from "../httpRequest"
import type { IRes, IResWithPage } from "../types"
import type { IUser } from "@shared/types/user"

export const userApi =  {
    getUserList(params: {
        page?: number,
        pageSize?: number,
        username?: string,
        phone?: string,
        role?: string,
        status?: string
    }): IResWithPage<IUser[]> {
        return httpRequest.get("/api/v1/user/list", {
            params
        })
    },
    getUserDetail(id: string): IRes<IUser> {
        return httpRequest.get("/api/v1/user/detail", {
            params: { id }
        })
    },
    createUser(data: Omit<IUser, '_id' | 'create_time'>): IRes<IUser> {
        return httpRequest.post("/api/v1/user/create", data)
    },
    updateUser(data: Partial<IUser> & { id: string }): IRes<IUser> {
        return httpRequest.post("/api/v1/user/update", data)
    },
    deleteUser(id: string): IRes<null> {
        return httpRequest.post("/api/v1/user/delete", { id })
    },
    batchDeleteUser(ids: string[]): IRes<{ deletedCount: number }> {
        return httpRequest.post("/api/v1/user/delete", { ids })
    },
    resetPassword(id: string, newPassword: string): IRes<null> {
        return httpRequest.post("/api/v1/user/reset-password", { id, newPassword })
    }
}